from django import forms
from django.core.exceptions import ValidationError


from app01.utils.form.bootsrapform import BootStrapForm, BootStrapModelForm
from app01 import models



class WikiModelForm(BootStrapModelForm):

    class Meta:
        model = models.Wiki
        exclude = ['project','depth']

    def __init__(self, request, *args, **kwargs):
        super().__init__(*args, **kwargs)

        # 找到想要的字段把他绑定的数据重置
        # 数据来源: 数据库中获取(显示当前项目的所有wiki)
        total_data_list = [("",'请选择')]
        data_list = models.Wiki.objects.filter(project=request.tracer.project).values_list('id','title')
        total_data_list.extend(data_list)
        self.fields['parent'].choices = total_data_list






